/**
 * 爆客码绑定场景
 * @param {validate_page} validate_page数据
 * @param {scene_data} scene_data 爆客码所需数据：
 * scene_data.scene	int	场景值
 * scene_data.type	int	1=h5,2=小程序
 * scene_data.url	string	跳转地址
 * scene_data.title	string	页面标题
 * scene_data.goods_id int	商品id
 * @returns Boolean 是否符合场景绑定跳转
 */
function bindDrainageScene(scene_data) {
  let validate_page = {};
  try {
    var value = wx.getStorageSync('validate_page')
    if (value) {
      validate_page = value?.drainage_code;
    }
  } catch (e) {}
  console.log(validate_page)
  if(!validate_page) return true;
  let {
    drainage_scene,
    has_add_employee
  } = validate_page;

  if (!has_add_employee) {
    if (scene_data.scene && drainage_scene.indexOf(scene_data.scene) > -1) {
      const pages = getCurrentPages()
      const currentPage = pages[pages.length - 1]
      const currentPath = currentPage.route
      const currentOptions = currentPage.options

      const app = getApp()
      scene_data.type = 2;
      scene_data.url = `/${currentPath}?${currentOptions}`;
      app.globalData.params = scene_data;

      wx.navigateTo({url: '/packageI/criticalCustomerShare/criticalCustomerShare?validate=1'})
      return false;
    }
    return true;
  }
  return true;
}

module.exports = {
  bindDrainageScene: bindDrainageScene
}